package br.ufla.pgcc.oomeasures.astvisitors;

import java.util.List;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class CommentRatioVisitor extends ASTVisitor {
	private int numberOfLinesOfCode = 0;
	private int numberOfCommentedLines = 0;
	private double commentsRatio = 0;


	@SuppressWarnings("unchecked")
	public boolean visit(CompilationUnit unit) {
		List<Comment> com = unit.getCommentList();
		for (Comment c : com) {
			
			if ((c.toString().split("\n").length) >= 1){
				numberOfCommentedLines ++;
			}
			commentsRatio++;
			c.delete();
		}
		numberOfLinesOfCode = unit.toString().split("\n").length;
		commentsRatio = (commentsRatio / numberOfLinesOfCode);
		return false;
	}

	public int getNumberOfCommentedLines(){
		return numberOfCommentedLines;
	}
	
	public double getCommentsRatio(){
		return commentsRatio;
	}
} 